Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

206
Vistas
Unit test -> Sinon + fluent-ffmpeg

I need some help with the following code:

const ffmpeg = require('fluent-ffmpeg'),
{PassThrough} = require('stream');

ffmpeg.setFfmpegPath('/opt/bin/ffmpeg');
ffmpeg.setFfprobePath('/opt/bin/ffprobe');

exports.wavCompilation = async (wavObjList, s3OutputFullPath) => {
    let command = ffmpeg();
    return new Promise(async (resolve, reject) => {

        const pt = new PassThrough()
        command
            .complexFilter(complexFilterList)
            .audioFrequency(44100)
            .audioChannels(2)
            .outputOptions('-map [audio]')
            .toFormat("wav")
            .output(pt, {end: true})
            .on('error', function (err, stdout, stderr) {
                console.log("stdout:\n" + stdout);
                console.log("stderr:\n" + stderr);
                if (err) {
                    console.log(err.message);
                    return reject("Error");
                }
            })
            .on('start', (commandLog) => printLog(commandLog))
            .on(`end`, () => console.info("end ffmpeg"))
            .run()

        resolve(***);
    });
}

Does anyone know how can I stub/mock/spy/fake "ffmpeg" ?

I use Sinon for unit tests and I'm trying to use proxyquire to mock "fluent-ffmpeg"

const sinon = require('sinon'),
proxyquire = require('proxyquire').noCallThru();

let ffmpegStub = {
    setFfmpegPath: () => {},
    setFfprobePath: () => {}
}

const ffmpegService = proxyquire('../services/ffmpeg-service/index', {
    'fluent-ffmpeg': ffmpegStub
});

for the methods setFfmpegPath and setFfprobePath it works but for the line:

let command = ffmpeg();

it says "ffmpeg is not a function"

I tried to add a default function such as:

let ffmpegStub = {
    default: () => {},
    setFfmpegPath: () => {},
    setFfprobePath: () => {}
}

but it also doesn't work and I have no idea now what I could do.

Please I need some fresh ideas, my goal is to catch the argument for "complexFilter" and assert it.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

No need of proxyquire.

I've got what I wanted with the following:

filterStub = sandbox.stub(ffmpeg.prototype, "complexFilter").returnsThis();
sandbox.stub(ffmpeg.prototype, "run").returnsThis();
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda